package com.njts.innerclass;

/**
 * @author David GE
 * Date  2025/11/21
 */
public class StaticKeyWord {
    //属性
    static String nationality="中国";
    String name="gzl";

    public static String getNationality() {
        return nationality;
    }

    public static void setNationality(String nationality) {
        StaticKeyWord.nationality = nationality;
        //name="g";//报错
    }

    public void test( ){
        System.out.println("我是非静态方法");
        setNationality("日本");
    }
    static {
        System.out.println("加载配置文件");
    }

    {
        System.out.println("我是构造代码块");
    }
    public static void main(String[] args) {
        // Static变量被类的实例对象所共享
        StaticKeyWord person = new StaticKeyWord();
        person.name = "葛兆磊";
        StaticKeyWord person2 = new StaticKeyWord();
        person.nationality = "zh";
        System.out.println(person.name);
        System.out.println(person2.name);
        System.out.println(person.getNationality());
        System.out.println(person2.getNationality());
        //test();//报错
        person.test();
        System.out.println(person.getNationality());
    }
}
